package com.xuecheng.media.controller;

import com.xuecheng.api.media.MediaAuditApi;
import com.xuecheng.api.media.model.dto.MediaDTO;
import com.xuecheng.api.media.model.qo.QueryMediaModel;
import com.xuecheng.api.media.model.vo.MediaAuditVO;
import com.xuecheng.common.domain.page.PageRequestParams;
import com.xuecheng.common.domain.page.PageVO;
import com.xuecheng.common.util.SecurityUtil;
import com.xuecheng.media.convert.MediaConvert;
import com.xuecheng.media.service.MediaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class MediaAuditController implements MediaAuditApi {

    @Autowired
    MediaService mediaService;

    public static final Long OPERATION_FLAG = -99887799L;

    @PostMapping("m/media/list")
    public PageVO queryMediaList(PageRequestParams params, @RequestBody QueryMediaModel model) {
        PageVO pageVO = mediaService.queryMediaByPage(params,model,OPERATION_FLAG);
        return pageVO;
    }

    @GetMapping("m/media/preview/{mediaId}")
    public String getPlayUrlByMediaId(@PathVariable Long mediaId) {
        Long companyId = SecurityUtil.getCompanyId();
        String playUrl = mediaService.getPlayUrlByMediaId(mediaId,companyId);
        return playUrl;
    }

    @PutMapping("m/media/audit")
    public void approveMedia(@RequestBody MediaDTO dto) {
//        MediaDTO dto = MediaConvert.INSTANCE.auditVo2dto(vo);

        mediaService.approveMedia(dto);

    }
}
